package org.zero.onlinesubject.controller;

import org.springframework.web.bind.annotation.*;
import org.zero.onlinesubject.common.vo.Result;
import org.zero.onlinesubject.common.vo.SignRecordsVo;
import org.zero.onlinesubject.entity.SignRecords;
import org.zero.onlinesubject.service.LiveRoomService;
import org.zero.onlinesubject.service.SignRecordsService;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/sign/api")
public class SignRecordsController {

    @Resource
    private SignRecordsService signRecordsService;

    // 发布签到信息
    @PostMapping("/publish")
    public Result<SignRecords> publishSign(@RequestBody SignRecords signRecords){
        SignRecords record = signRecordsService.insertSignRecord(signRecords);
        return record!=null ? Result.ok("发布签到成功",record) : Result.error(500,"发布签到失败");
    }

    // 通过直播间id号获取签到信息
    @GetMapping("/getLiveSignInfo")
    public Result<SignRecords> getLiveSignInfo(String liveId){
        SignRecords records = signRecordsService.getLiveSignInfo(liveId);
        return Result.ok(records);
    }

    // 确认签到
    @GetMapping("/updateSignCount")
    public Result<String> updateSignCount(Integer signID,Integer fromID){
        Boolean flag = signRecordsService.updateSignCount(signID,fromID);
        return flag ? Result.ok("签到成功") : Result.error(500,"签到失败");
    }

    // 获取签到信息对于接收者来说
    @GetMapping("/getSignInfo")
    public Result<SignRecordsVo> getSignRecordsInfo(String liveId){
        SignRecordsVo vo = signRecordsService.getSignRecordsVo(liveId);
        return vo !=null ? Result.ok(vo):Result.error(500,"当前不存在签到信息");
    }

    // 获取签到信息列表
    @GetMapping("/signInfoList")
    public Result<List<SignRecordsVo>> getSignInfoList(Integer fromId){
        List<SignRecordsVo> voList = signRecordsService.getSignInfoList(fromId);
        return Result.ok(voList);
    }
}
